package com.ruoyi.web.controller.tool;

import com.alibaba.druid.filter.config.ConfigTools;

import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;

public class EncryptPassword {
    public static void main(String[] args) throws Exception {
        String password = "password01!";
        try {
            // 利用阿里的ConfigTools工具类来生成一对公私钥，私钥用来加密，公钥用来解密
            String[] keyParis = ConfigTools.genKeyPair(512);
//            String privateKey = keyParis[0];
//            String publicKey = keyParis[1];

            String privateKey = "MIIBUwIBADANBgkqhkiG9w0BAQEFAASCAT0wggE5AgEAAkEArOFGayIZbgAfrhAOTthW3XFN/ENSvLRHKymFjyuSmFRoF216LglqwAFvFAFxMr2xmGA/cMpWcEcxBEw/7ZDS7wIDAQABAkBYNBO2g05QJjYDm+OA7LXdA3sTctHav2v0JJolAskneEpNGAjRF2rUXRB2lXDQS4GW92DH23KQ/D6WBCnUJgWxAiEA20Kj9tNeilhy7byDIXgwmFvGCTmgf/2ncS+9SplGfVcCIQDJ2Rw/HwoPFgLrPrAmctVMHbueH5x6bLj42/i25fdAKQIgVINaSfBtF2xCWGp6LPNz37Y4HiQtPkhaOyGIl/F+nx8CIAioWlDOyQSqogdrEe0kQcfZAqIeovyRS0HJVZqqtHc5AiBII8nL+NjV7I/62GpFykknySEjZvhR/JHy+7dBu34naw==";
            String publicKey = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKzhRmsiGW4AH64QDk7YVt1xTfxDUry0RysphY8rkphUaBdtei4JasABbxQBcTK9sZhgP3DKVnBHMQRMP+2Q0u8CAwEAAQ==";

            System.out.println("privateKey="+privateKey);
            System.out.println("publicKey="+publicKey);
            String encryptPassword = ConfigTools.encrypt(privateKey, password);
            System.out.println("encryptPassword="+encryptPassword);
            String decryptPassword = ConfigTools.decrypt(publicKey, encryptPassword);
            System.out.println("decryptPassword="+decryptPassword);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (NoSuchProviderException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }



//        password = ConfigTools.decrypt(
//                "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJFNlGABykxjRooxnWYin0c20EzfVq3n18IZntfDYbdpIL/gc67bFKnttCktVpjfbWdc2sA7nVe4DIk54A4jg2ECAwEAAQ==",
//                "B8qlWtHL+TDlFNRv1xvy+EQdc43oF6vsZk6896rfUKQSWdl10yvhKtJ4TCa6NPvtOLJTI1F1jhk1XXZ4fKqZZw==");
//        System.out.println("解密密码：" + password);
    }
}
